package com.twu.biblioteca;

import java.io.PrintStream;
import java.util.HashMap;


public class BibliotecaApp {

    private HashMap<String, Book> books;
    private MenuIO menu;
    private PrintStream printStream;
    private MovieLibrary movieLibrary ;

    public BibliotecaApp(PrintStream printStream, HashMap<String, Book> books, MenuIO menu, MovieLibrary movieLibrary) {
        menu.setApp(this);
        this.movieLibrary = movieLibrary;
        this.books = books;
        this.menu = menu;
        this.printStream = printStream;

    }

    public Book getBook(String bookName) {
        return books.get(bookName);

    }


    public boolean reserveBook(String bookName) {
        Book b = this.getBook(bookName);
        if (b != null && !b.isReserved()) {
            String message = getString();
            b.reserve();
            printStream.println(message);
            return true;
        } else {
            printStream.println("Sorry we don't have that book yet.");
            return false;
        }
    }

    private String getString() {
        return "Thank You! Enjoy the book.";
    }

    public MenuIO getMenu() {
        return menu;
    }

    public void showBooks() {
        for (String book : books.keySet()) {
            printStream.println(book);

        }
    }

    public void start() {
        menu.welcome();
        menu.showMenuOptions();
        menu.processMenuOption(menu.readMenuOption());
    }

    public void showMovies()
    {
      printStream.println("Movie      Year      Director      Rating");
      movieLibrary.printAllMovies();
    }
}
